<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="医生类型：">
          <el-select v-model="formInline.doctorType" filterable>
            <el-option label="矫正" value="1"></el-option>
            <el-option label="种植" value="2"></el-option>
            <el-option label="全科" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上架状态：">
          <el-select v-model="formInline.isPublished" filterable>
            <el-option label="是" :value="true"></el-option>
            <el-option label="否" :value="false"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否搜索热门：">
          <el-select v-model="formInline.isFeatured" filterable>
            <el-option label="是" :value="true"></el-option>
            <el-option label="否" :value="false"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="城市：">
          <city-select v-model="formInline.cityId"  />
        </el-form-item>
        
        <el-form-item label="关键词：">
          <el-input v-model="formInline.key" placeholder="请输入医生姓名"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="getList">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <el-button type="primary" size="small" @click="addDoctor()">新增医生</el-button>
        <!-- <el-button type="default" size="small" @click="addDoctor()">热门关键词</el-button> -->
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="doctorName" label="医生姓名" />
        <el-table-column prop="doctorType" label="医生类型" show-overflow-tooltip>
          <template slot-scope="{row}">{{doctorTyps[row.doctorType]||'--'}}</template>
        </el-table-column>
        <el-table-column prop="cityName" label="城市" />
        <el-table-column prop="sortTime" label="排序时间" show-overflow-tooltip />
        <el-table-column prop="isPublished" label="上架状态" show-overflow-tooltip>
          <template slot-scope="{row}">{{row.isPublished?'是':'否'}}</template>
        </el-table-column>
        <el-table-column prop="isPublished" label="是否搜索热门" show-overflow-tooltip>
          <template slot-scope="{row}">{{row.isFeatured?'是':'否'}}</template>
        </el-table-column>
        <el-table-column prop="createdAt" label="添加时间" show-overflow-tooltip />
        <el-table-column prop="addedBy" label="添加人" show-overflow-tooltip />
        <el-table-column prop="address" label="操作" width="200px" align="center">
          <template slot-scope="{ row }">
            <el-link type="primary" class="el_link" :underline="false" :id="row.id" @click="addDoctor(row.id)">编辑</el-link>
            <el-link type="danger" class="el_link" :underline="false" :id="row.id" @click="remove(row)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>
      
<script>
import { showToast, showModal, deepClone } from "@/common/util";
import { GET_DOCTOR_LIST, DELECT_DOCTOR_INFO } from "@/http/interface";
import CitySelect from '@/components/common/city.vue';
export default {
  components:{
    CitySelect
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      orderTime: [],
      loading: false,
      doctorTyps: {
        1: "矫正",
        2: "种植",
        3: "全科",
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.orderTime = [];
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));
      let n = this.orderTime;

      if (n && n.length > 0) {
        oParams.sDate = n[0];
        oParams.eDate = n[1];
      }

      oParams.current = this.pageNumber;
      oParams.size = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_DOCTOR_LIST(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.records || [];
        _this.pageTotal = obj.total;
      });
    },

    // 新增医院
    addDoctor(id) {
      this.$router.push({ name: "addDoctor", query: { id: id } });
    },

    // 删除医生
    remove(row) {
      let _this = this;
      showModal({
        message: `确认删除${row.doctorName}医生吗？`,
        showCancelButton: true,
        success: function () {
          let oParams = {};
          oParams.id = row.id;
          DELECT_DOCTOR_INFO(oParams).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "删除成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },
  },
};
</script>
      
<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
      